Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Part of Android Support: screenshot testing #4411

Merged
merged 8 commits into from
Jan 29, 2025

Conversation

vaslabs
Copy link
Contributor

@vaslabs vaslabs commented Jan 27, 2025

Background

Screenshot testing is a way to test UIs and in Android's case, typically without the need of running an emulator. This is achieved in recent developments with the usage of Compose and Previews (the same functionality that generates previews in android studio).

The typical flow is:

  1. A base line is generated, with screenshots being committed into the application's repo
  2. Regression tests subsequently, compare the screenshots
  3. For new UIs that devs decide to add coverage or agreed changes, baseline is updated

Further Reading: https://developer.android.com/studio/preview/compose-screenshot-testing

Provided in this PR

This PR, while it has in mind the full flow support, only provides the means to generate screenshots and run diffs with the same tools that AGP is using. At the same time, we keep the test task compatibility with Mill so we don't need to implement any custom runner tasks.

Generating screenshots

Using the same tool as AGP, the compose-preview-renderer, which has undocumented cli arguments. However, these can be found by running the respective gradle task in a sample Android studio project

./gradlew  updateDebugScreenshotTest

Then, given the generated data, the PR worked towards generating the file computing classpaths and other needed files similarly

CLI arguments generated by Gradle for the preview tool

Currently these screenshots are ephemeral, and this PR is not concerned by adding support for version control on the screenshot base. The plan is for a future PR to make it easier for the users to customise the behaviour (e.g. choose the path)

Testing screenshots

AGP uses the screenshot-validation-junit-engine. This PR provides similar functionality but hooking into Mill's testing infrastructure instead of Gradle.

Example App

The example App was set up initially with AGP and then a mill version was constructed with 2 differences:

  1. Only 1 screen configuration is provided for the simplicity of this first attempt
  2. Although compose preview is technically working, it is only kept in the screenTest module, again for the simplicity of this PR and not doing any changes to the compose support in the main android kotlin module yet.

Future developments / Not yet implemented in this PR

  • Baseline management
  • Updating previews (this can be done already, but with a crude overwrite)
  • More examples and more screen sizes and UI configurations
  • Discover classes and methods automatically

irodotos7 and others added 5 commits January 27, 2025 12:31
prototyping

Progressing

Compiling

Generates screenshots

Cleanups and fmt
@vaslabs vaslabs marked this pull request as ready for review January 28, 2025 08:22
@vaslabs
Copy link
Contributor Author

vaslabs commented Jan 28, 2025

there is a failure in the javalib native examples, but I don't think it's related to my changes.

@lihaoyi
Copy link
Member

lihaoyi commented Jan 29, 2025

I think the code looks fine, just some comments about the provenance of the code to better understand why it is the way it is.

For some reason Github is not letting me resolve the branch conflict, so you may have to tick the checkbox in the PR to let maintainers update it

@vaslabs vaslabs force-pushed the android/screenshot-testing branch from e46627e to a46eddd Compare January 29, 2025 08:28
@vaslabs
Copy link
Contributor Author

vaslabs commented Jan 29, 2025

I think the code looks fine, just some comments about the provenance of the code to better understand why it is the way it is.

For some reason Github is not letting me resolve the branch conflict, so you may have to tick the checkbox in the PR to let maintainers update it

thanks, there were conflicts with the main branch, T.log => Task.log, so I changed that bit of code on this PR as per your recommendation

@lihaoyi lihaoyi merged commit 916628b into com-lihaoyi:main Jan 29, 2025
31 checks passed
@lefou lefou added this to the 0.12.6 milestone Jan 29, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants